/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Gattini
 */
public class Parser {

    public static String parseString(Object o) {
        if (o == null) {
            return "";
        } else {
            return o.toString();
        }
    }

    public static Date parseStringToDate(String d) {
        SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
        try {
            return f.parse(d);
        } catch (Exception ex) {
            return null;
        }
    }

    public static String parseDateToString(Date d) {
        SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
        try {
            return f.format(d);
        } catch (Exception ex) {
            return null;
        }
    }
    
        public static String parseDateTimeToString(Date d) {
        SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        try {
            return f.format(d);
        } catch (Exception ex) {
            return null;
        }
    }

    public static Date parseStringToDateTime(String d) {
        SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        try {
            return f.parse(d);
        } catch (Exception ex) {
            return null;
        }
    }
}
